package com.orhon.smartcampus.modules.course.fetcher;


import com.orhon.smartcampus.modules.course.dao.CoursesDao;
import com.orhon.smartcampus.modules.course.entity.Courses;
import com.orhon.smartcampus.modules.course.gqlModel.GQLCourses;
import com.orhon.smartcampus.modules.course.mm.CoursesMapper;
import graphql.schema.DataFetcher;
import graphql.schema.DataFetchingEnvironment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class CourseFetcher implements DataFetcher {

    @Autowired
    CoursesDao courseDao;
    
    @Override
    public Object get(DataFetchingEnvironment env) throws Exception {
        int id = Integer.parseInt(env.getArgument("id").toString());

        String hql = "from Courses where deleted_at = null and id = "+id;
        Courses item = courseDao.findId(hql, null);
        if(item!=null) {
            GQLCourses courses = CoursesMapper.MAPPER.toCourses(item);
            return courses;
        }
		return null;
    }


}
